#include "aky_program/aky_com_include.h"


static void my_event_cb(lv_obj_t* obj, lv_event_t event);
void set_label_table_text_fmt(uint8_t row, uint8_t col, const char *fmt, ...);
void label_table_init(void);
void load_mem(void);
void mem_chart_init(void);
void switch_show_stat(uint8_t stat);
void set_drag_stat(uint8_t stat);

lv_obj_t* obj_sub;
lv_obj_t* obj_table;
lv_obj_t* obj_title;
lv_obj_t* obj_line;
#define TABLE_MAIN_WINDOW_WIDTH 980
#define TABLE_MAIN_WINDOW_HIGHT 300

#define TABLE_TITLE_WINDOW_WIDTH 980


#define TABLE_ROW_MAX 30
#define TABLE_ROW_GAP_VAL 50

#define TABLE_COL_MAX 6
#define TABLE_COL_GAP_VAL (TABLE_MAIN_WINDOW_WIDTH / TABLE_COL_MAX)

#define TABLE_SUB_WINDOW_WIDTH TABLE_MAIN_WINDOW_WIDTH
#define TABLE_SUB_WINDOW_HIGHT (TABLE_ROW_GAP_VAL * TABLE_ROW_MAX)
lv_obj_t * line_table_row[TABLE_ROW_MAX];

static lv_point_t line_points_row[TABLE_ROW_MAX * 2];

lv_obj_t * line_table_col[TABLE_COL_MAX];
static lv_point_t line_points_col[TABLE_COL_MAX * 2];
lv_obj_t * label_table[TABLE_ROW_MAX][TABLE_COL_MAX];
lv_obj_t * line_table_col_title[TABLE_COL_MAX];
static lv_point_t line_points_col_title[TABLE_COL_MAX * 2];
lv_obj_t * label_table_title[TABLE_COL_MAX];

lv_obj_t* obj_net_table[TABLE_ROW_MAX]; //显示记忆的上传状态

lv_obj_t * line_table_col_slider[1];
static lv_point_t line_points_col_slider[2];

static lv_obj_t * label_name;
static lv_obj_t * label_gender;
static lv_obj_t * label_age;
static lv_obj_t *tc_area_back;          //
static lv_obj_t *tc_area_bp_curve;          //血压曲线
static lv_obj_t *tc_area_back_sub;          //血压曲线 返回
static lv_obj_t *slider_mem;          //
static lv_obj_t *tc_area_block;          //挡住一部分触摸区域

uint8_t flag_enter_bp_curve = 0;
uint8_t flag_mem_empty = 0;

#define CHART_WINDOW_WIDTH 1000
#define CHART_WINDOW_HEIGHT 350
#define CHART_SUB_WINDOW_HEIGHT CHART_WINDOW_HEIGHT
#define CHART_HOR_GAP_VAL 160 //每个横坐标之间的间隔
#define CHART_TICK_MAX MAX_MEM_SIZE
lv_obj_t * obj_chart_window;
lv_obj_t * chart_1;
lv_chart_series_t * ser1;
lv_chart_series_t * ser2;
lv_chart_series_t * ser3;

static lv_obj_t *img_mem_chart; //记忆图表的返回
s_mem_t chart_mem_buf[MAX_MEM_SIZE] = {0};
char chart_x_tick_buf[MAX_MEM_SIZE * 15];
char buf_temp[50];


/*
 * 界面回调函数
 */
static void screen009_on_timer(void *user_data)
{
    /* 界面定时器回调函数 */
    screen_flush_pro();
    if (get_spk_recogni_info() == SPK_BACK)
    {
        clr_spk_recogni_info();
        synwit_ui_load_screen(SCREEN005);        
    }
    if (get_spk_recogni_info() == BP_CHART)
    {
        clr_spk_recogni_info();
        lv_event_send(tc_area_bp_curve,LV_EVENT_CLICKED,NULL);
    }

}

static void screen009_start(synwit_id_t screen_id)
{
    /* 在界面被显示给用户前，这个接口会被调用。 */
    flag_enter_bp_curve = 0;
    flag_mem_empty = 0;

    label_name = synwit_ui_find_lv_obj(WIDGET_LABEL31);
    label_gender = synwit_ui_find_lv_obj(WIDGET_LABEL33);
    label_age = synwit_ui_find_lv_obj(WIDGET_LABEL35);

    tc_area_back = synwit_ui_find_lv_obj(WIDGET_TOUCH_23);
    tc_area_bp_curve = synwit_ui_find_lv_obj(WIDGET_TOUCH_22);
    chart_1 = synwit_ui_find_lv_obj(WIDGET_CHART_1);
    img_mem_chart = synwit_ui_find_lv_obj(WIDGET_IMAGE20);
    tc_area_back_sub = synwit_ui_find_lv_obj(WIDGET_TOUCH_29);
    slider_mem = synwit_ui_find_lv_obj(WIDGET_SLIDER_2);
    tc_area_block = synwit_ui_find_lv_obj(WIDGET_TOUCH_25);

	lv_font_t* font_key_board = synwit_ui_font_load("S:spi:wqyMicroHeiMono_40.hmf", false);
    if (font_key_board != NULL)
    {
    	lv_obj_set_style_local_text_font(label_name, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_key_board);	
    	lv_obj_set_style_local_text_font(label_gender, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_key_board);	
        /* code */
    }

    label_table_init();
    mem_chart_init();
    switch_show_stat(0);
    set_drag_stat(0);
    load_mem();

    lv_label_set_text_fmt(label_name, "%s",g_s_mem_index.user_name_buf);
    lv_label_set_text_fmt(label_gender, "%s",get_gender_str(g_s_mem_index.gender));
    lv_label_set_text_fmt(label_age, "%s",g_s_mem_index.age_buf);

    lv_obj_set_event_cb(tc_area_back, my_event_cb);   /*Assign an event callback*/
    lv_obj_set_event_cb(tc_area_bp_curve, my_event_cb);   /*Assign an event callback*/
    lv_obj_set_event_cb(tc_area_back_sub, my_event_cb);   /*Assign an event callback*/
    lv_obj_set_event_cb(slider_mem, my_event_cb);   /*Assign an event callback*/

    // 打开下面的注释可以为本界面开启一个每100ms触发一次的定时器
    screen_init();
    synwit_ui_start_scr_timer(10, NULL);
}

static void screen009_stop(synwit_id_t screen_id)
{
    /* 准备切换到其它界面前，这个接口会被调用。 */
    screen_stop();
}

static int screen009_favorite_stop_policy()
{
    /* 函数返回值表示本界面结束时，希望采用的资源管理策略 */

    /* 资源管理策略(主要影响本界面再次进入时的加载速度):
     *    0: 系统推荐，释放当前界面引用的资源，保留控件及控件状态。可获得平衡的界面切换性能和内存消耗
     *    1: 释放当前界面引用的资源，并删除所有控件。
     *    2: 保留当前界面的所有资源及控件。可以获得最佳的界面切换性能，但内存消耗较大
     */
    return 0;
}


/*
 * 界面注册对象
 */
synwit_screen_callback_t screen009_cb_obj = {
    .favorite_stop_policy = screen009_favorite_stop_policy,
    .on_screen_start = screen009_start,
    .on_screen_stop = screen009_stop,
    .on_screen_timer = screen009_on_timer,
};

void set_label_table_text_fmt(uint8_t row, uint8_t col, const char *fmt, ...)
{
    char buff[50];  //用于存放转换后的数据 [长度]
    uint16_t i=0;
	uint8_t r=0,n=0;
    va_list arg_ptr;
    va_start(arg_ptr,fmt);
    vsnprintf(buff, 20,fmt,arg_ptr);//数据转换
    // printf("row=%d col=%d s=%s\r\n",row,col,buff);
    lv_label_set_text_fmt(label_table[row][col], "%s",buff);

    va_end(arg_ptr);
}
static void my_event_cb(lv_obj_t* obj, lv_event_t event)
{
    lv_coord_t x_temp;
    lv_coord_t y_temp;
    uint16_t slider_val;

    uint16_t pos_y;
    lv_coord_t width_main;
    lv_coord_t width_sub;
    static uint32_t u32_tick_last = 0;

    off_time_clr();
    if (flag_enter_bp_curve == 1)
    {
        if (obj == chart_1)
        {
            if (event == LV_EVENT_PRESSED || event == LV_EVENT_PRESSING || event == LV_EVENT_DRAG_END)
            {
                x_temp = lv_obj_get_x(chart_1);
                width_main = lv_obj_get_width(obj_chart_window);
                width_sub = lv_obj_get_width(chart_1);
                printf("x_temp = %d\n",x_temp);
                if (x_temp < (width_main - width_sub))
                {
                    lv_obj_set_pos(chart_1, (width_main - width_sub),0);
                }
                if (x_temp > 0)
                {
                    lv_obj_set_pos(chart_1, 0, 0);
                }
            }
        }
        if (obj == tc_area_back_sub)
        {
            if (event == LV_EVENT_CLICKED)
            {
                flag_enter_bp_curve = 0;
                switch_show_stat(0);
            }
        }
        return;
    }
    if (obj == slider_mem)
    {
        // if (event == LV_EVENT_RELEASED)
        // {
        //     slider_val = -lv_slider_get_value(slider_mem);
        //     printf("LV_EVENT_RELEASED slider_val:%d\n", slider_val);
        //     pos_y = (TABLE_SUB_WINDOW_HIGHT * slider_val) / 100;
        //     if (pos_y > TABLE_SUB_WINDOW_HIGHT - TABLE_MAIN_WINDOW_HIGHT)
        //     {
        //         pos_y = TABLE_SUB_WINDOW_HIGHT - TABLE_MAIN_WINDOW_HIGHT;
        //     }
            
        //     printf("pos_y:%d\n", pos_y);
            
        //     lv_obj_set_y(obj_sub, -pos_y);
        // }
        if (event == LV_EVENT_PRESSING)
        {
            // if (g_u32_tick_cnt - u32_tick_last > 300 / 10)
            {
                u32_tick_last = g_u32_tick_cnt;
                slider_val = -lv_slider_get_value(slider_mem);
                printf("LV_EVENT_PRESSING slider_val:%d\n", slider_val);
                pos_y = (TABLE_SUB_WINDOW_HIGHT * slider_val) / 100;
                if (pos_y > TABLE_SUB_WINDOW_HIGHT - TABLE_MAIN_WINDOW_HIGHT)
                {
                    pos_y = TABLE_SUB_WINDOW_HIGHT - TABLE_MAIN_WINDOW_HIGHT;
                }
                
                printf("pos_y:%d\n", pos_y);

                {
                    lv_obj_set_y(obj_sub, -pos_y);
                }
            }
        }
    }
    if (obj == obj_sub)
    {
        y_temp = lv_obj_get_y(obj_sub);

        if (event == LV_EVENT_PRESSING || event == LV_EVENT_DRAG_END)
        {

            if (y_temp < (TABLE_MAIN_WINDOW_HIGHT - TABLE_SUB_WINDOW_HIGHT))
            {
                lv_obj_set_pos(obj_sub, 0, (TABLE_MAIN_WINDOW_HIGHT - TABLE_SUB_WINDOW_HIGHT));
            }
            if (y_temp > 0)
            {
                lv_obj_set_pos(obj_sub, 0, 0);
            }
        }
        else if (event == LV_EVENT_RELEASED)
        {
            slider_val =  ((-y_temp) * 100) / (TABLE_SUB_WINDOW_HIGHT - TABLE_MAIN_WINDOW_HIGHT);
            lv_slider_set_value(slider_mem,-slider_val, LV_ANIM_OFF); // 初始值设为 0（顶部）
        }
        
    }

    if (obj == tc_area_back)
    {
        if (event == LV_EVENT_CLICKED)
        {
            synwit_ui_load_screen(SCREEN005);
        }
    }
    if (obj == tc_area_bp_curve)
    {
        if (event == LV_EVENT_CLICKED)
        {
            // if (flag_mem_empty == 0)
            {
                flag_enter_bp_curve = 1;
                switch_show_stat(1);
            }
        }
    }
}

#define TABLE_SLIDER_WIDTH (20)
void label_table_init(void)
{
    /* 在界面被显示给用户前，这个接口会被调用。 */
    static uint8_t flag_init_onece = 0;
    lv_coord_t x_temp;
    lv_coord_t y_temp;

    if (flag_init_onece == 1)
    {
        return;
    }
    else
    {
        flag_init_onece = 1;
    }
    static lv_style_t style;
    lv_style_init(&style);
    lv_style_set_radius(&style, LV_STATE_DEFAULT, 5);
    /*Make a gradient*/
    lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
    lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_WHITE);
    lv_style_set_border_width(&style, LV_STATE_DEFAULT, 0);
    lv_style_set_outline_width(&style, LV_STATE_DEFAULT, 0);


    lv_style_set_pad_top(&style, LV_STATE_DEFAULT, 0);
    lv_style_set_pad_bottom(&style, LV_STATE_DEFAULT, 0);
    obj_table = lv_obj_create(lv_scr_act(), NULL);
    lv_obj_set_pos(obj_table, 20, 190);
    lv_obj_set_size(obj_table, TABLE_MAIN_WINDOW_WIDTH, TABLE_MAIN_WINDOW_HIGHT);
    lv_obj_set_hidden(obj_table, false);
    lv_obj_add_style(obj_table, LV_OBJ_PART_MAIN, &style);
    lv_obj_set_click(obj_table, false);
    lv_obj_set_drag(obj_table, false);


    obj_title = lv_obj_create(lv_scr_act(), NULL);
    lv_obj_set_pos(obj_title, 20, 140);
    lv_obj_set_size(obj_title, TABLE_TITLE_WINDOW_WIDTH, TABLE_ROW_GAP_VAL + 3);
    lv_obj_set_hidden(obj_title, false);
    lv_obj_add_style(obj_title, LV_OBJ_PART_MAIN, &style);
    lv_obj_set_click(obj_title, false);
    lv_obj_set_drag(obj_title, false);


    static lv_style_t style_sub;
    lv_style_init(&style_sub);
    lv_style_set_radius(&style_sub, LV_STATE_DEFAULT, 0);
    /*Make a gradient*/
    lv_style_set_bg_opa(&style_sub, LV_STATE_DEFAULT, LV_OPA_COVER);
    lv_style_set_bg_color(&style_sub, LV_STATE_DEFAULT, LV_COLOR_WHITE);

    lv_style_set_border_width(&style_sub, LV_STATE_DEFAULT, 0);
    // lv_style_set_border_color(&style_sub, LV_STATE_DEFAULT, LV_COLOR_BLACK);

    lv_style_set_outline_width(&style_sub, LV_STATE_DEFAULT, 0);
    // lv_style_set_outline_color(&style_sub, LV_STATE_DEFAULT, LV_COLOR_BLACK);
//    lv_style_set_border_color(&style_sub,LV_STATE_DEFAULT|LV_STATE_FOCUSED,LV_COLOR_BLACK);        //设置样式边框颜色
//    lv_style_set_border_width(&style_sub,LV_STATE_DEFAULT|LV_STATE_FOCUSED,4);                  //设置样式边框宽度
//    lv_style_set_border_opa(&style_sub,LV_STATE_DEFAULT|LV_STATE_FOCUSED, LV_OPA_COVER);            //设置样式边框透明度
//    lv_style_set_border_side(&style_sub,LV_STATE_DEFAULT|LV_STATE_FOCUSED,LV_BORDER_SIDE_FULL); //设置样式边框显示范围

//     lv_style_set_pad_all(&style_sub,LV_STATE_DEFAULT|LV_STATE_FOCUSED,10);

    obj_sub = lv_obj_create(obj_table, NULL);
    lv_obj_set_pos(obj_sub, 0, 0);
    lv_obj_set_size(obj_sub, TABLE_SUB_WINDOW_WIDTH, TABLE_SUB_WINDOW_HIGHT);
    lv_obj_set_hidden(obj_sub, false);
    lv_obj_add_style(obj_sub, LV_OBJ_PART_MAIN, &style_sub);
    lv_obj_set_drag_dir(obj_sub,LV_DRAG_DIR_VER);
    lv_obj_set_event_cb(obj_sub, my_event_cb);   /*Assign an event callback*/
    // lv_obj_set_state(obj_sub, LV_STATE_FOCUSED);
    lv_obj_set_drag_throw(obj_sub, false);

    {
        for (uint8_t i = 0; i < TABLE_ROW_MAX; i++)
        {
            obj_net_table[i] = lv_obj_create(obj_sub, NULL);
            
            lv_obj_set_pos(obj_net_table[i], 0, TABLE_ROW_GAP_VAL * i);
            lv_obj_set_size(obj_net_table[i], TABLE_MAIN_WINDOW_WIDTH, TABLE_ROW_GAP_VAL);
            lv_obj_set_hidden(obj_net_table[i], true);
            lv_obj_add_style(obj_net_table[i], LV_OBJ_PART_MAIN, &style_sub);
            lv_obj_set_drag_throw(obj_net_table[i], false);
            lv_obj_set_click(obj_net_table[i], false);
            lv_obj_set_drag(obj_net_table[i], false);
            lv_obj_set_style_local_bg_color(obj_net_table[i], LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
        }
    }


/*Create an array for the points of the line*/


static lv_point_t line_points[] = { {0, 0}, {TABLE_SUB_WINDOW_WIDTH, 0}, {TABLE_SUB_WINDOW_WIDTH, TABLE_SUB_WINDOW_HIGHT}, {0, TABLE_SUB_WINDOW_HIGHT}, {0, 0}, };
/*Create style*/
static lv_style_t style_line;
lv_style_init(&style_line);
lv_style_set_line_width(&style_line, LV_STATE_DEFAULT, 2);
lv_style_set_line_color(&style_line, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_line_rounded(&style_line, LV_STATE_DEFAULT, true);
/*Create a line and apply the new style*/
lv_obj_t * line1;
line1 = lv_line_create(obj_sub, NULL);
lv_line_set_points(line1, line_points, 5); /*Set the points*/
lv_obj_add_style(line1, LV_LINE_PART_MAIN, &style_line); /*Set the points*/

static lv_point_t line_points_title[] = { {0, 0}, {TABLE_TITLE_WINDOW_WIDTH, 0}, {TABLE_TITLE_WINDOW_WIDTH, TABLE_ROW_GAP_VAL + 1}, {0, TABLE_ROW_GAP_VAL + 1}, {0, 0}, };
/*Create style*/
/*Create a line and apply the new style*/
lv_obj_t * line_title;//
line_title = lv_line_create(obj_title, NULL);
lv_style_set_line_width(&style_line, LV_STATE_DEFAULT, 2);
lv_line_set_points(line_title, line_points_title, 5); /*Set the points*/
lv_obj_add_style(line_title, LV_LINE_PART_MAIN, &style_line); /*Set the points*/


for (uint8_t i = 0; i < TABLE_ROW_MAX; i++)
{
    line_table_row[i] = lv_line_create(obj_sub, NULL);
    line_points_row[i * 2].x = 2;
    line_points_row[i * 2].y = 2 + i * TABLE_ROW_GAP_VAL;
    line_points_row[i * 2 + 1].x = TABLE_TITLE_WINDOW_WIDTH  -2;
    line_points_row[i * 2 + 1].y = 2 + i * TABLE_ROW_GAP_VAL;
    lv_line_set_points(line_table_row[i], &line_points_row[i * 2], 2); /*Set the points*/
    lv_obj_add_style(line_table_row[i], LV_LINE_PART_MAIN, &style_line); /*Set the points*/
}




for (uint8_t i = 0; i < TABLE_COL_MAX; i++)
{


    line_table_col[i] = lv_line_create(obj_sub, NULL);
    line_points_col[i * 2].x = 2 + i * TABLE_COL_GAP_VAL;
    line_points_col[i * 2].y = 2;
    line_points_col[i * 2 + 1].x = 2 + i * TABLE_COL_GAP_VAL;
    line_points_col[i * 2 + 1].y = TABLE_SUB_WINDOW_HIGHT;
    if (i == TABLE_COL_MAX - 1)
    {
        line_points_col[i * 2].x -= TABLE_SLIDER_WIDTH;
        line_points_col[i * 2 + 1].x = line_points_col[i * 2].x;
    }
    lv_line_set_points(line_table_col[i], &line_points_col[i * 2], 2); /*Set the points*/
    lv_obj_add_style(line_table_col[i], LV_LINE_PART_MAIN, &style_line); /*Set the points*/
}

for (uint8_t i = 0; i < TABLE_COL_MAX; i++)
{
    line_table_col_title[i] = lv_line_create(obj_title, NULL);
    line_points_col_title[i * 2].x = 2 + i * TABLE_COL_GAP_VAL;
    line_points_col_title[i * 2].y = 2;
    line_points_col_title[i * 2 + 1].x = 2 + i * TABLE_COL_GAP_VAL;
    line_points_col_title[i * 2 + 1].y = TABLE_ROW_GAP_VAL;
    if (i == TABLE_COL_MAX - 1)
    {
        line_points_col_title[i * 2].x -= TABLE_SLIDER_WIDTH;
        line_points_col_title[i * 2 + 1].x = line_points_col[i * 2].x;
    }

    lv_line_set_points(line_table_col_title[i], &line_points_col_title[i * 2], 2); /*Set the points*/
    lv_obj_add_style(line_table_col_title[i], LV_LINE_PART_MAIN, &style_line); /*Set the points*/
}


// static lv_point_t line_points_row[] = { {2, 52}, {978, 52},{2, 102}, {978, 102},};
// lv_line_set_points(line2, line_points_row, 4); /*Set the points*/

	lv_font_t* font_label_table = synwit_ui_font_load("S:spi:SourceHanSansSC-Medium-28.hmf", false);

    for (uint8_t i = 0; i < TABLE_ROW_MAX; i++)
    {
        for (uint8_t j = 0; j < TABLE_COL_MAX; j++)
        {
            label_table[i][j] = lv_label_create(obj_sub, NULL);
            
            lv_label_set_long_mode(label_table[i][j], LV_LABEL_LONG_BREAK);
            //  lv_obj_set_size(label_table[i][j], TABLE_COL_GAP_VAL, TABLE_ROW_GAP_VAL);
            // lv_obj_set_style_local_text_font(label_table[i][j], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_22);
            if (font_label_table != NULL)
            {
            	lv_obj_set_style_local_text_font(label_table[i][j], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_label_table);	
            }
            lv_label_set_align(label_table[i][j], LV_LABEL_ALIGN_CENTER);   
            lv_obj_set_click(label_table[i][j], false);
            lv_obj_set_drag(label_table[i][j], false);
            // lv_label_set_text_fmt(label_table[i][j], "row:%d col:%d", i, j);
            lv_obj_set_width(label_table[i][j], TABLE_COL_GAP_VAL);
             lv_obj_set_height(label_table[i][j], TABLE_ROW_GAP_VAL);
             x_temp = 2 + j * TABLE_COL_GAP_VAL;
             y_temp = 2 +i * TABLE_ROW_GAP_VAL + (TABLE_ROW_GAP_VAL / 8);
             if (j == TABLE_COL_MAX - 2)
             {
                x_temp -= (TABLE_SLIDER_WIDTH - 10);
             }
             if (j == TABLE_COL_MAX - 1)
             {
                x_temp -= TABLE_SLIDER_WIDTH;
             }
            lv_obj_set_pos(label_table[i][j], x_temp, y_temp);
        }
        
    }

    {
        for (uint8_t i = 0; i < TABLE_COL_MAX; i++)
        {
            label_table_title[i] = lv_label_create(obj_title, NULL);
            
            lv_label_set_long_mode(label_table_title[i], LV_LABEL_LONG_BREAK);
            //  lv_obj_set_size(label_table[i][j], TABLE_COL_GAP_VAL, TABLE_ROW_GAP_VAL);
            // lv_obj_set_style_local_text_font(label_table_title[i], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_22);
            if (font_label_table != NULL)
            {
            	lv_obj_set_style_local_text_font(label_table_title[i], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_label_table);	
            }
            lv_label_set_align(label_table_title[i], LV_LABEL_ALIGN_CENTER);   
            lv_obj_set_click(label_table_title[i], false);
            lv_obj_set_drag(label_table_title[i], false);
            // lv_label_set_text_fmt(label_table_title[i], "col:%d",i);
            lv_obj_set_width(label_table_title[i], TABLE_COL_GAP_VAL);
             lv_obj_set_height(label_table_title[i], TABLE_ROW_GAP_VAL);
             x_temp = 2 + i * TABLE_COL_GAP_VAL;
             y_temp = 2 + (TABLE_ROW_GAP_VAL / 8);
             if (i == TABLE_COL_MAX - 2)
             {
                x_temp -= (TABLE_SLIDER_WIDTH - 10);
             }
             if (i == TABLE_COL_MAX - 1)
             {
                x_temp -= (TABLE_SLIDER_WIDTH - 10);
             }
            lv_obj_set_pos(label_table_title[i], x_temp,y_temp);
        }
        
    }



    lv_label_set_text_fmt(label_table_title[0],"日期");
    lv_label_set_text_fmt(label_table_title[1],"时间");
    lv_label_set_text_fmt(label_table_title[2],"右侧血压");
    lv_label_set_text_fmt(label_table_title[3],"左侧血压");
    lv_label_set_text_fmt(label_table_title[4],"心率");
    lv_label_set_text_fmt(label_table_title[5],"训练时长");
    

    lv_obj_set_parent(tc_area_block,obj_table);
    lv_obj_align(tc_area_block,obj_table,LV_ALIGN_IN_TOP_RIGHT,0,0);

    lv_obj_set_ext_click_area(obj_table, 0, 20, 0, 0);

    lv_obj_set_parent(slider_mem,obj_table);
    lv_slider_set_value(slider_mem,0, LV_ANIM_OFF); // 初始值设为 0（顶部）
    lv_obj_align(slider_mem,obj_table,LV_ALIGN_IN_TOP_RIGHT,-8,1);
    lv_obj_set_size(slider_mem, TABLE_SLIDER_WIDTH, 300);
    lv_obj_set_ext_click_area(slider_mem, 20, 20, 20, 20);
    lv_obj_set_style_local_pad_top(slider_mem,LV_SLIDER_PART_BG, LV_STATE_DEFAULT, 20);
    lv_obj_set_style_local_pad_bottom(slider_mem,LV_SLIDER_PART_BG, LV_STATE_DEFAULT, 20);
    lv_obj_set_style_local_bg_opa(slider_mem,LV_SLIDER_PART_BG, LV_STATE_DEFAULT, LV_OPA_TRANSP);

    // line_table_col_slider[0] = lv_line_create(obj_sub, NULL);
    // line_points_col_slider[0 * 2].x = (TABLE_MAIN_WINDOW_WIDTH - 20) - 2;
    // line_points_col_slider[0 * 2].y = 2;
    // line_points_col_slider[0 * 2 + 1].x = line_points_col_slider[0 * 2].x;
    // line_points_col_slider[0 * 2 + 1].y = TABLE_SUB_WINDOW_HIGHT;

    // lv_line_set_points(line_table_col_slider[0], &line_points_col_slider[0 * 2], 2); /*Set the points*/
    // lv_obj_add_style(line_table_col_slider[0], LV_LINE_PART_MAIN, &style_line); /*Set the points*/

    lv_obj_set_style_local_border_width(slider_mem,LV_SLIDER_PART_BG, LV_STATE_DEFAULT, 1);
    lv_obj_set_style_local_border_opa(slider_mem,LV_SLIDER_PART_BG, LV_STATE_DEFAULT, LV_OPA_COVER);
}

void table_label_all_set_empty(void)
{
    for (uint8_t i = 0; i < TABLE_ROW_MAX; i++)
    {
        for (uint8_t j = 0; j < TABLE_COL_MAX; j++)
        {
            set_label_table_text_fmt(i,j,"");
        }
        lv_obj_set_hidden(obj_net_table[i], true);
    }
}

void mem_chart_all_set_empty(void)
{
    lv_obj_set_size(chart_1,CHART_HOR_GAP_VAL + 60, CHART_SUB_WINDOW_HEIGHT);
    lv_chart_set_point_count(chart_1, 0);
    lv_chart_set_x_tick_texts(chart_1, "     no mem", 1,LV_CHART_AXIS_DRAW_LAST_TICK);

    lv_chart_refresh(chart_1); /*Required after direct set*/
}

#define LOAD_MEM_MAX 15
#define LOAD_ROW_MAX 30

void load_mem(void)
{
    uint16_t row_index = 0;
    uint16_t mem_cnt = 0;
    uint16_t chart_index = 0;

    uint16_t cur_mem_index_last = 0;
    g_s_mem_index = flash_get_mem_index_data(g_e_user,&g_e_flash_err,MAIN_ADDR);
    cur_mem_index_last = g_s_mem_index.cur_mem_index;
    row_index = 0;
    mem_cnt = 0;
    table_label_all_set_empty();
    while (1) 
    {
        if (g_s_mem_index.cur_mem_index == 0 || g_e_flash_err == AKY_FLASH_ERR)
        {
            // 记忆空
            flag_mem_empty = 1;
            set_drag_stat(0);
            table_label_all_set_empty();
            break;
        }
        else if (g_s_mem_index.cur_mem_index > 6 || g_s_mem_index.flag_mem_overwrite == 1)
        {
            set_drag_stat(1);
        }
        
        g_s_mem = flash_get_mem_data(g_e_user,g_s_mem_index.cur_mem_index,&g_e_flash_err,MAIN_ADDR);
        {
            if (g_s_mem.flag_ful_dat == 1)
            {
                int64_t start_time;//计算开始的时间
                s_time_t s_time_start;
                start_time = timetostamp(g_s_mem.s_time);
                start_time = (start_time - (((60 * g_s_mem.s_train_time.min) + (g_s_mem.s_train_time.secon)) * 1000));
                s_time_start = timestamp_to_s_time(start_time);
                
                set_label_table_text_fmt(row_index,0,"20%d/%d/%d",g_s_mem.s_time.year,g_s_mem.s_time.month,g_s_mem.s_time.day);
                set_label_table_text_fmt(row_index,1,"%d:%02d:%02d",g_s_mem.s_time.hour,g_s_mem.s_time.min,g_s_mem.s_time.secon);
                set_label_table_text_fmt(row_index,2,"%d/%d",g_s_mem.s_right_bp.sys,g_s_mem.s_right_bp.dia);
                set_label_table_text_fmt(row_index,3,"%d/%d",g_s_mem.s_left_bp.sys,g_s_mem.s_left_bp.dia);
                set_label_table_text_fmt(row_index,4,"%d",g_s_mem.s_left_bp.pul);
                if (g_s_mem.s_train_time.secon == 0 && g_s_mem.s_train_time.min != 0)
                {
                    set_label_table_text_fmt(row_index,5,"%d分钟",g_s_mem.s_train_time.min);
                }
                else
                {
                    set_label_table_text_fmt(row_index,5,"%d分钟%d秒",g_s_mem.s_train_time.min,g_s_mem.s_train_time.secon);
                }
                if (g_s_mem.flag_syn == 1)
                {
                    lv_obj_set_hidden(obj_net_table[row_index], true);
                }
                else
                {
                    lv_obj_set_hidden(obj_net_table[row_index], false);
                }

                row_index++;

                set_label_table_text_fmt(row_index,0,"20%d/%d/%d",s_time_start.year,s_time_start.month,s_time_start.day);
                set_label_table_text_fmt(row_index,1,"%d:%02d:%02d",s_time_start.hour,s_time_start.min,s_time_start.secon);
                set_label_table_text_fmt(row_index,2,"%d/%d",g_s_mem.s_right_bp_start.sys,g_s_mem.s_right_bp_start.dia);
                set_label_table_text_fmt(row_index,3,"%d/%d",g_s_mem.s_left_bp_start.sys,g_s_mem.s_left_bp_start.dia);
                set_label_table_text_fmt(row_index,4,"%d",g_s_mem.s_left_bp_start.pul);
                set_label_table_text_fmt(row_index,5,"0分钟0秒");
                if (g_s_mem.flag_syn == 1)
                {
                    lv_obj_set_hidden(obj_net_table[row_index], true);
                }
                else
                {
                    lv_obj_set_hidden(obj_net_table[row_index], false);
                }
                    
            }
            else
            {
                set_label_table_text_fmt(row_index,0,"20%d/%d/%d",g_s_mem.s_time.year,g_s_mem.s_time.month,g_s_mem.s_time.day);
                set_label_table_text_fmt(row_index,1,"%d:%02d:%02d",g_s_mem.s_time.hour,g_s_mem.s_time.min,g_s_mem.s_time.secon);
                set_label_table_text_fmt(row_index,2,"%d/%d",g_s_mem.s_right_bp.sys,g_s_mem.s_right_bp.dia);
                set_label_table_text_fmt(row_index,3,"%d/%d",g_s_mem.s_left_bp.sys,g_s_mem.s_left_bp.dia);
                set_label_table_text_fmt(row_index,4,"%d",g_s_mem.s_left_bp.pul);
                if (g_s_mem.s_train_time.secon == 0 && g_s_mem.s_train_time.min != 0)
                {
                    set_label_table_text_fmt(row_index,5,"%d分钟",g_s_mem.s_train_time.min);
                }
                else
                {
                    set_label_table_text_fmt(row_index,5,"%d分钟%d秒",g_s_mem.s_train_time.min,g_s_mem.s_train_time.secon);
                }
                if (g_s_mem.flag_syn == 1)
                {
                    lv_obj_set_hidden(obj_net_table[row_index], true);
                }
                else
                {
                    lv_obj_set_hidden(obj_net_table[row_index], false);
                }    
            }
        }

        g_s_mem_index.cur_mem_index--;
        if(g_s_mem_index.flag_mem_overwrite == 1)
        {
            if (g_s_mem_index.cur_mem_index == 0)
            {
                g_s_mem_index.cur_mem_index = g_s_mem_index.mem_set;
            }
            else if (g_s_mem_index.cur_mem_index == cur_mem_index_last)
            {
                break;                
            }     
        }
        else
        {
            if (g_s_mem_index.cur_mem_index == 0)
            {
                break;
            }            
        }


        row_index++;
        if (row_index > 6)
        {
            set_drag_stat(1);
        }
        if (row_index >= LOAD_ROW_MAX)
        {
            break;
        }
        mem_cnt++;
        if (mem_cnt >= LOAD_MEM_MAX)
        {
            break;
        }
        
    }

    g_s_mem_index = flash_get_mem_index_data(g_e_user,&g_e_flash_err,MAIN_ADDR);
    cur_mem_index_last = g_s_mem_index.cur_mem_index;
    chart_index = 0;
    while (1) 
    {
        if (g_s_mem_index.cur_mem_index == 0 || g_e_flash_err == AKY_FLASH_ERR)
        {
            // 记忆空
            flag_mem_empty = 1;
            mem_chart_all_set_empty();
            break;
        }
        // else if (g_s_mem_index.cur_mem_index > 7 || g_s_mem_index.flag_mem_overwrite == 1)
        // {
        //     set_drag_stat(2);
        // }
        
        g_s_mem = flash_get_mem_data(g_e_user,g_s_mem_index.cur_mem_index,&g_e_flash_err,MAIN_ADDR);
        {
            chart_mem_buf[chart_index] = g_s_mem;
        }
        chart_index++;
        if (chart_index >= CHART_TICK_MAX)
        {
            break;
        }
        g_s_mem_index.cur_mem_index--;
        if(g_s_mem_index.flag_mem_overwrite == 1)
        {
            if (g_s_mem_index.cur_mem_index == 0)
            {
                g_s_mem_index.cur_mem_index = g_s_mem_index.mem_set;
            }
            else if (g_s_mem_index.cur_mem_index == cur_mem_index_last)
            {
                break;                
            }     
        }
        else
        {
            if (g_s_mem_index.cur_mem_index == 0)
            {
                break;
            }            
        }



    }
    if (flag_mem_empty ==0)
    {
        printf("chart_index:%d\n",chart_index);
        // if (chart_index <= 7)
        // {
        // }
        // else
        // {
        //     lv_obj_set_size(chart_1, (chart_index - 1) * CHART_HOR_GAP_VAL, CHART_SUB_WINDOW_HEIGHT);
        // }
        lv_obj_set_size(chart_1,chart_index * CHART_HOR_GAP_VAL, CHART_SUB_WINDOW_HEIGHT);
        if (chart_index * CHART_HOR_GAP_VAL > CHART_WINDOW_WIDTH)
        {
            set_drag_stat(2);
        }

        lv_chart_set_point_count(chart_1, chart_index);
        volatile uint16_t i;
        volatile uint16_t for_init;
        for_init = (chart_index - 1);
        for (i = for_init; i >= 0; i--)
        {
            lv_chart_set_next(chart_1, ser1,(lv_coord_t) chart_mem_buf[i].s_left_bp.sys);
            lv_chart_set_next(chart_1, ser2,(lv_coord_t) chart_mem_buf[i].s_left_bp.dia);
            lv_chart_set_next(chart_1, ser3,(lv_coord_t) chart_mem_buf[i].s_left_bp.pul);
            if (i == for_init)
            {
                //第一组
                sprintf(chart_x_tick_buf, "     %d/%d %d:%02d\n", chart_mem_buf[i].s_time.month, chart_mem_buf[i].s_time.day, chart_mem_buf[i].s_time.hour, chart_mem_buf[i].s_time.min);
            }
            else
            {
                if (i == 0)
                {
                    //最后一组
                    sprintf(buf_temp, "%d/%d %d:%02d", chart_mem_buf[i].s_time.month, chart_mem_buf[i].s_time.day, chart_mem_buf[i].s_time.hour, chart_mem_buf[i].s_time.min);
                }
                else
                {
                    sprintf(buf_temp, "%d/%d %d:%02d\n", chart_mem_buf[i].s_time.month, chart_mem_buf[i].s_time.day, chart_mem_buf[i].s_time.hour, chart_mem_buf[i].s_time.min);
                }
                strcat(chart_x_tick_buf, buf_temp);
            }
            if (i == 0)
            {
                AKY_ASM_NOP();
                break;
            }
            
        }
        // printf("     10/22 22:01\n10/22 22:02\n10/22 22:03\n10/22 22:04\n10/22 22:05\n10/22 22:06\n10/22 22:07\n10/22 22:08");
        // printf("%s",chart_x_tick_buf);
        lv_chart_set_x_tick_texts(chart_1, chart_x_tick_buf, 1,LV_CHART_AXIS_DRAW_LAST_TICK);
        lv_chart_refresh(chart_1); /*Required after direct set*/
    }
    

}



void mem_chart_init(void)
{
    static uint8_t flag_init_onece = 0;
    if (flag_init_onece == 1)
    {
        return;
    }
    else
    {
        flag_init_onece = 1;
    }

    static lv_style_t style;
    lv_style_init(&style);
    lv_style_set_radius(&style, LV_STATE_DEFAULT, 5);
    /*Make a gradient*/
    lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
    lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_WHITE);
    lv_style_set_border_width(&style, LV_STATE_DEFAULT, 0);
    lv_style_set_outline_width(&style, LV_STATE_DEFAULT, 0);


    lv_style_set_pad_top(&style, LV_STATE_DEFAULT, 0);
    lv_style_set_pad_bottom(&style, LV_STATE_DEFAULT, 0);

    obj_chart_window = lv_chart_create(lv_scr_act(), NULL);
    lv_obj_set_pos(obj_chart_window, 11, 128);
    lv_obj_set_size(obj_chart_window, CHART_WINDOW_WIDTH, CHART_WINDOW_HEIGHT);
    lv_obj_set_hidden(obj_chart_window, true);
    lv_obj_add_style(obj_chart_window, LV_OBJ_PART_MAIN, &style);
    lv_obj_set_click(obj_chart_window, false);
    lv_obj_set_drag(obj_chart_window, false);



    /*Create a chart*/
    lv_obj_set_parent(chart_1, obj_chart_window);
    lv_obj_set_pos(chart_1, 0, 0);
    lv_obj_set_click(chart_1, true);
    lv_obj_set_drag(chart_1, true);
    lv_obj_set_drag_dir(chart_1,LV_DRAG_DIR_HOR);
    lv_obj_set_event_cb(chart_1, my_event_cb);   /*Assign an event callback*/
    lv_obj_set_drag_throw(chart_1, false);
    lv_chart_set_y_range(chart_1, LV_CHART_AXIS_PRIMARY_Y, 0, 255);
    lv_chart_set_y_tick_texts(chart_1, "          ", 0,LV_CHART_AXIS_SKIP_LAST_TICK);
    // lv_chart_set_y_tick_texts(chart_1, "255\n200\n100\n0", 1,LV_CHART_AXIS_DRAW_LAST_TICK);
    ser1 = lv_chart_add_series(chart_1, LV_COLOR_RED);
    ser2 = lv_chart_add_series(chart_1, LV_COLOR_BLUE);
    ser3 = lv_chart_add_series(chart_1, lv_color_hex(0x00ff56));
	lv_font_t* font_label_y = synwit_ui_font_load("S:spi:SourceHanSansSC-Medium-28.hmf", false);

    //固定y轴刻度值
    lv_obj_t *label_y_tick[5];
    for (uint8_t i = 0; i < 5; i++)
    {
        label_y_tick[i] = lv_label_create(obj_chart_window, NULL);
        lv_label_set_long_mode(label_y_tick[i], LV_LABEL_LONG_BREAK);
        if (font_label_y != NULL)
        {
        	lv_obj_set_style_local_text_font(label_y_tick[i], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_label_y);	
        }
        lv_label_set_align(label_y_tick[i], LV_LABEL_ALIGN_LEFT);   
        lv_obj_set_click(label_y_tick[i], false);
        lv_obj_set_drag(label_y_tick[i], false);
        lv_obj_set_width(label_y_tick[i], 80);
        lv_obj_set_height(label_y_tick[i], 30);
    }
    lv_obj_set_pos(label_y_tick[0],0,1);
    lv_obj_set_pos(label_y_tick[1],0,65);
    lv_obj_set_pos(label_y_tick[2],0,170);
    lv_obj_set_pos(label_y_tick[3],0,220);
    lv_obj_set_pos(label_y_tick[4],0,280);

    lv_label_set_text_fmt(label_y_tick[0], "255-");
    lv_label_set_text_fmt(label_y_tick[1], "200-");
    lv_label_set_text_fmt(label_y_tick[2], "100-");
    lv_label_set_text_fmt(label_y_tick[3], "   50-");
    lv_label_set_text_fmt(label_y_tick[4], "     0-");


    //  lv_obj_set_size(label_table[i][j], TABLE_COL_GAP_VAL, TABLE_ROW_GAP_VAL);
    // lv_obj_set_style_local_text_font(label_table_title[i], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_montserrat_22);
    // lv_label_set_text_fmt(label_table_title[i], "col:%d",i);
    // lv_obj_set_size(chart_1, 29 * CHART_HOR_GAP_VAL, CHART_SUB_WINDOW_HEIGHT);
//     lv_chart_set_point_count(chart_1, 30);
// for (uint8_t i = 0; i < 30; i++)
// {
//     lv_chart_set_next(chart_1, ser1, 122);
//     lv_chart_set_next(chart_1, ser2, 99);
//     lv_chart_set_next(chart_1, ser3, 66);
// }

    // sprintf(chart_x_tick_buf, "     10/22 22:01\n10/22 22:02\n10/22 22:03\n10/22 22:04\n10/22 22:05\n10/22 22:06\n10/22 22:07\n10/22 22:08\n10/22 22:08\n10/22 22:08");
    // sprintf(chart_x_tick_buf, "     10/22 22:01\n10/22 22:02\n10/22 22:03\n10/22 22:04\n10/22 22:05\n10/22 22:06\n10/22 22:07\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08");

    // lv_chart_set_x_tick_texts(chart_1, chart_x_tick_buf, 1,LV_CHART_AXIS_DRAW_LAST_TICK);

    // lv_chart_set_x_tick_texts(chart_1, "     10/22 22:01\n10/22 22:02\n10/22 22:03\n10/22 22:04\n10/22 22:05\n10/22 22:06\n10/22 22:07\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08\n10/22 22:08", 1,LV_CHART_AXIS_DRAW_LAST_TICK);


    // lv_obj_set_size(chart_1, 7 * CHART_HOR_GAP_VAL, CHART_SUB_WINDOW_HEIGHT);
    // lv_chart_set_x_tick_texts(chart_1, "     10/22 22:01\n10/22 22:02\n10/22 22:03\n10/22 22:04\n10/22 22:05\n10/22 22:06\n10/22 22:07\n10/22 22:08", 1,LV_CHART_AXIS_DRAW_LAST_TICK);
    // lv_chart_set_point_count(chart_1, 8);
    // /*Add two data series*/ 
    // lv_chart_set_next(chart_1, ser1, 122);
    // lv_chart_set_next(chart_1, ser2, 99);
    // lv_chart_set_next(chart_1, ser3, 66);

    // lv_chart_set_next(chart_1, ser1, 133);
    // lv_chart_set_next(chart_1, ser2, 88);
    // lv_chart_set_next(chart_1, ser3, 77);

    // lv_chart_set_next(chart_1, ser1, 199);
    // lv_chart_set_next(chart_1, ser2, 100);
    // lv_chart_set_next(chart_1, ser3, 77);

    // lv_chart_set_next(chart_1, ser1, 222);
    // lv_chart_set_next(chart_1, ser2, 111);
    // lv_chart_set_next(chart_1, ser3, 66);

    // lv_chart_set_next(chart_1, ser1, 230);
    // lv_chart_set_next(chart_1, ser2, 133);
    // lv_chart_set_next(chart_1, ser3, 66);

    // lv_chart_set_next(chart_1, ser1, 240);
    // lv_chart_set_next(chart_1, ser2, 144);
    // lv_chart_set_next(chart_1, ser3, 115);

    // lv_chart_set_next(chart_1, ser1, 200);
    // lv_chart_set_next(chart_1, ser2, 155);
    // lv_chart_set_next(chart_1, ser3, 122);

    // lv_chart_set_next(chart_1, ser1, 222);
    // lv_chart_set_next(chart_1, ser2, 166);
    // lv_chart_set_next(chart_1, ser3, 155);
    // /*Set the next points on 'ser1'*/
    // lv_chart_set_next(chart_1, ser1, 10);
    // lv_chart_set_next(chart_1, ser1, 10);
    // lv_chart_set_next(chart_1, ser1, 10);
    // lv_chart_set_next(chart_1, ser1, 10);
    // lv_chart_set_next(chart_1, ser1, 10);
    // lv_chart_set_next(chart_1, ser1, 10);
    // lv_chart_set_next(chart_1, ser1, 10);
    // lv_chart_set_next(chart_1, ser1, 30);
    // lv_chart_set_next(chart_1, ser1, 70);
    // lv_chart_set_next(chart_1, ser1, 90);

    // lv_chart_set_next(chart_1, ser2, 20);
    // lv_chart_set_next(chart_1, ser2, 20);
    // lv_chart_set_next(chart_1, ser2, 20);
    // lv_chart_set_next(chart_1, ser2, 20);
    // lv_chart_set_next(chart_1, ser2, 20);
    // lv_chart_set_next(chart_1, ser2, 20);
    // lv_chart_set_next(chart_1, ser2, 20);
    // lv_chart_set_next(chart_1, ser2, 30);
    // lv_chart_set_next(chart_1, ser2, 40);
    // lv_chart_set_next(chart_1, ser2, 50);

    // lv_chart_set_next(chart_1, ser3, 30);
    // lv_chart_set_next(chart_1, ser3, 30);
    // lv_chart_set_next(chart_1, ser3, 30);
    // lv_chart_set_next(chart_1, ser3, 30);
    // lv_chart_set_next(chart_1, ser3, 30);
    // lv_chart_set_next(chart_1, ser3, 30);
    // lv_chart_set_next(chart_1, ser3, 30);
    // lv_chart_set_next(chart_1, ser3, 40);
    // lv_chart_set_next(chart_1, ser3, 50);
    // lv_chart_set_next(chart_1, ser3, 60);

    lv_chart_refresh(chart_1); /*Required after direct set*/

}


void switch_show_stat(uint8_t stat)
{
    if (stat == 0)
    {
        lv_obj_set_hidden(obj_table, false);
        lv_obj_set_hidden(slider_mem,false);
        lv_obj_set_hidden(obj_chart_window, true);
        lv_obj_set_hidden(img_mem_chart, true);

    }
    else if (stat == 1)
    {
        lv_obj_set_hidden(obj_table,true);
        lv_obj_set_hidden(slider_mem,true);
        lv_obj_set_hidden(obj_chart_window, false);
        lv_obj_set_hidden(img_mem_chart, false);


    }
    
}

void set_drag_stat(uint8_t stat)
{
    if (stat == 0)
    {
        lv_obj_set_drag_throw(obj_sub, false);
        lv_obj_set_click(obj_sub, false);
        lv_obj_set_drag(obj_sub, false);

        lv_obj_set_click(slider_mem, false);
        
        lv_obj_set_drag_throw(chart_1, false);
        lv_obj_set_click(chart_1, false);
        lv_obj_set_drag(chart_1, false);
        lv_obj_set_pos(obj_sub, 0, 0);
        lv_obj_set_pos(chart_1, 0, 0);
        lv_slider_set_value(slider_mem,0, LV_ANIM_OFF); // 初始值设为 0（顶部）
    }
    else if (stat == 1)
    {
        lv_obj_set_drag_throw(obj_sub, false);
        lv_obj_set_click(obj_sub, true);
        lv_obj_set_drag(obj_sub, true);
        
        lv_obj_set_click(slider_mem, true);
    }
    else if (stat == 2)
    {
        lv_obj_set_drag_throw(chart_1, false);
        lv_obj_set_click(chart_1, true);
        lv_obj_set_drag(chart_1, true);
    }
}


